const http = require('http');
const router = require("koa-router")();
var fs = require('fs');
const Koa = require('koa');
const cors = require("koa2-cors");//导入跨域模块
const app = new Koa();
app.use(router.routes());
app.use(cors({
    'Access-Control-Allow-Headers':'Content-Type, Content-Length, Authorization, Accept, X-Requested-With , yourHeaderFeild'
}));
const  file_name="E:/1.txt";
// 定义允许跨域的origin
const allowOrigins = [
    "http://127.0.0.1:3000",
    "http://192.168.0.1:8083"
];
router.get('/import',async (ctx) => {
    // 读取文件内容
    let data1 = '';
    await new Promise((resolve, reject) => {
        fs.readFile(file_name, (err, data) => {
            data1 = data;
            resolve()
        });
    });
    console.log(data1);
    ctx.body =data1;

});
app.use(router.routes());
app.use(router.allowedMethods());
app.listen(3000);
console.log("listen on 3000");